unit CharterFailure;

interface

uses
  Database,
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, Buttons, ExtCtrls, ColorGrd, Mask, Menus,
  ComCtrls, JvExMask, JvSpin;

type
  TFormCharterFailure = class(TForm)
    BtnOK: TBitBtn;
    BtnCancel: TBitBtn;
    BtnHelp: TBitBtn;
    MainMenu1: TMainMenu;
    Main1: TMenuItem;
    MenuHelp: TMenuItem;
    BoxFailures: TGroupBox;
    Label8: TLabel;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Edit1: TEdit;
    Edit2: TEdit;
    Edit3: TEdit;
    Edit4: TEdit;
    Edit5: TEdit;
    BoxStubs: TGroupBox;
    Label5: TLabel;
    Label6: TLabel;
    Label7: TLabel;
    Label9: TLabel;
    Label10: TLabel;
    Edit12: TEdit;
    Edit13: TEdit;
    Edit14: TEdit;
    Edit15: TEdit;
    Edit16: TEdit;
    Label11: TLabel;
    Edit11: TEdit;
    Bevel1: TBevel;
    Label12: TLabel;
    Bevel2: TBevel;
    LabelSeconds: TLabel;
    Label13: TLabel;
    CheckNonCardinal: TCheckBox;
    CheckCompleteonStub: TCheckBox;
    Label14: TLabel;
    EditRefresh: TEdit;
    Panel1: TPanel;
    Status: TLabel;
    Label15: TLabel;
    Edit19: TEdit;
    Label16: TLabel;
    Label17: TLabel;
    BoxRoomLabel: TGroupBox;
    Label18: TLabel;
    EditLabel: TEdit;
    Label19: TLabel;
    BoxDirections: TGroupBox;
    Label20: TLabel;
    EditN: TEdit;
    Label21: TLabel;
    EditS: TEdit;
    Label22: TLabel;
    EditNW: TEdit;
    Label23: TLabel;
    EditSW: TEdit;
    Label24: TLabel;
    EditW: TEdit;
    Label25: TLabel;
    EditNE: TEdit;
    Label26: TLabel;
    EditE: TEdit;
    Label27: TLabel;
    EditSE: TEdit;
    Label28: TLabel;
    EditU: TEdit;
    Label29: TLabel;
    EditD: TEdit;
    EditU2: TEdit;
    EditD2: TEdit;
    EditNW2: TEdit;
    EditW2: TEdit;
    EditSW2: TEdit;
    EditSE2: TEdit;
    EditE2: TEdit;
    EditNE2: TEdit;
    EditN2: TEdit;
    EditS2: TEdit;
    BtnReset: TBitBtn;
    Spin1: TJvSpinEdit;
    procedure BtnCancelClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure BtnOKClick(Sender: TObject);
    procedure BtnHelpClick(Sender: TObject);
    procedure Spin1Exit(Sender: TObject);
    procedure Spin1Change(Sender: TObject);
    procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure BtnResetClick(Sender: TObject);
  private
    { Private declarations }
    function PassedCheck(str: string): boolean;
  public
    { Public declarations }
    linked: boolean;
    amt: integer;
  end;

var
  FormCharterFailure: TFormCharterFailure;

implementation

{$R *.DFM}

procedure TFormCharterFailure.FormCreate(Sender: TObject);
begin
  linked:=false;
  amt:=0;
end;

procedure TFormCharterFailure.BtnHelpClick(Sender: TObject);
begin
  Datawell.Help('charter_setup');
end;

procedure TFormCharterFailure.BtnCancelClick(Sender: TObject);
begin
  close;
end;

procedure TFormCharterFailure.BtnOKClick(Sender: TObject);
begin
  if not PassedCheck(Edit12.text) then begin Edit12.selectall; Edit12.setfocus; exit; end;
  if not PassedCheck(Edit13.text) then begin Edit13.selectall; Edit13.setfocus; exit; end;
  if not PassedCheck(Edit14.text) then begin Edit14.selectall; Edit14.setfocus; exit; end;
  if not PassedCheck(Edit15.text) then begin Edit15.selectall; Edit15.setfocus; exit; end;
  if not PassedCheck(Edit16.text) then begin Edit16.selectall; Edit16.setfocus; exit; end;
  linked:=true;
  amt:=trunc(Spin1.value);
  close;
end;

function TFormCharterFailure.PassedCheck(str: string): boolean;
var work: string;
begin
  result:=false;
  if str = '' then begin
    result:=true;
    exit;
  end;
  if pos('{@}',str) < 1 then begin
    messagedlg('You must have a {@} in the stub grab to represent the exits',
      mtinformation,[mbok],0);
    exit;
  end;
  work:=copy(str,pos('{@}',str)+4,99999);
  if pos('{@}',work) > 0 then begin
    messagedlg('You can only have one {@} in the stub grab',
      mtinformation,[mbok],0);
    exit;
  end;
  str:=Datawell.subs('{@}','*',str);
  if pos('**',str) > 0 then begin
    messagedlg('You cannot have *''s or {@}''s next to one another, nor two {@}''s',
      mtinformation,[mbok],0);
    exit;
  end;
  result:=true;
end;

procedure TFormCharterFailure.Spin1Exit(Sender: TObject);
begin
  if TJvSpinEdit(sender).value < 0 then TJvSpinEdit(sender).value:=1;
  if TJvSpinEdit(sender).value > 60 then TJvSpinEdit(sender).value:=60;
end;

procedure TFormCharterFailure.Spin1Change(Sender: TObject);
begin
  if Spin1.value = 1 then LabelSeconds.caption:='second'
  else LabelSeconds.caption:='seconds';
end;

procedure TFormCharterFailure.FormMouseMove(Sender: TObject;
  Shift: TShiftState; X, Y: Integer);
begin
  Status.caption:=' '+(sender as TControl).hint;
end;

procedure TFormCharterFailure.BtnResetClick(Sender: TObject);
begin
  if messagedlg('Are you sure?',mtconfirmation,[mbyes,mbcancel],0) = mrcancel then exit;
  EditU.text:='up';
  EditD.text:='down';
  EditNW.text:='northwest';
  EditN.text:='north';
  EditNE.text:='northeast';
  EditW.text:='west';
  EditE.text:='east';
  EditSW.text:='southwest';
  EditS.text:='south';
  EditSE.text:='southeast';
  EditU2.text:='u';
  EditD2.text:='d';
  EditNW2.text:='nw';
  EditN2.text:='n';
  EditNE2.text:='ne';
  EditW2.text:='w';
  EditE2.text:='e';
  EditSW2.text:='sw';
  EditS2.text:='s';
  EditSE2.text:='se';
end;

end.

